#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 300010;
int n, m;
int a[N], s[N];
vector<int> alls;
vector<PII> add, query;

int find(int x){
	int i=-1,j=alls.size();
	while(i+1!=j){
		int mid=j+i>>1;
		if(alls[mid]<x) i=mid;
		else j=mid;
	}	
	return j;
}
int main(){
	cin>>n>>m;
	for(int i=0;i<n;++i){
		int x,c;
		cin>>x>>c;
		add.push_back({x,c});
		alls.push_back(x);
	}
	
	for(int i=0;i<m;i++){
		int l,r;
		cin>>l>>r;
		query.push_back({l,r});
		alls.push_back(l);
		alls.push_back(r);
	}
	
	sort(alls.begin(),alls.end());
	alls.erase(unique(alls.begin(),alls.end()),alls.end());
	
	for(int i=0;i<add.size();++i){
		int k=find(add[i].first);
		a[k]+=add[i].second;
        //vector不能进行随机存入操作其次不如数组模拟更快
        }
	 
	s[0]=a[0];
	for(int i=1;i<alls.size();++i) s[i]=s[i-1]+a[i];
 
    for(int i=0;i<query.size();++i){
		int l=find(query[i].first),r=find(query[i].second);
	
		cout<<s[r]-s[l-1]<<endl;
	}

	return 0;
}
/*#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int, int> PII;
const int N = 300010;
int n, m;
int a[N], s[N];
vector<int> alls;
vector<PII> add, query;

int find(int x)
{
    int l = 0, r = alls.size() - 1;
    while (l < r)
    {
        int mid = l + r >> 1;
        if (alls[mid] >= x) r = mid;
        else l = mid + 1;
    }
    return r + 1;
}

int main()
{
    cin >> n >> m;
    for (int i = 0; i < n; i++)
    {
        int x, c;
        cin >> x >> c;
        add.push_back({ x, c });
        alls.push_back(x);
    }


    cout << endl << "add:";
    for (int i = 0; i < add.size(); i++)  cout << add[i].first << " " << add[i].second << endl;
    cout << "alls：" << endl;
    for (int i = 0; i < alls.size(); i++)   cout << alls[i] << " ";
    cout << endl << endl;

    for (int i = 0; i < m; i++)
    {
        int l, r;
        cin >> l >> r;
        query.push_back({ l, r });

        alls.push_back(l);
        alls.push_back(r);
    }

    cout << endl << "add:";
    for (int i = 0; i < add.size(); i++)  cout << add[i].first << " " << add[i].second << endl;
    cout << "query:" << endl;
    for (int i = 0; i < query.size(); i++) cout << query[i].first << " " << query[i].second << endl;
    cout << "alls：" << endl;
    for (int i = 0; i < alls.size(); i++)   cout << alls[i] << " ";
    cout << endl;
    


    sort(alls.begin(), alls.end());
    alls.erase(unique(alls.begin(), alls.end()), alls.end());
    cout << endl;

    cout << "alls：" << endl;
    for (int i = 0; i < alls.size(); i++)   cout << alls[i] << " ";
    cout << endl;

    for (auto item : add)
    {
        int x = find(item.first);
        a[x] += item.second;
    }
    cout << "a[]:" << endl;
    for (int i = 0; i<20; i++) { cout << a[i] << " "; }
    cout << endl;

    // 预处理前缀和
    for (int i = 1; i <= alls.size(); i++) s[i] = s[i - 1] + a[i];

    cout << "s[]:" << endl;
    for (int i = 0; i<20; i++) { if (s[i] == 0) break;  cout << s[i] << " "; }
    cout << endl;

    // 处理询问
    for (auto item : query)
    {
        int l = find(item.first), r = find(item.second);
        cout << s[r] - s[l - 1] << endl;
    }

    return 0;
}*/
